<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/

// Joomla security
defined('_JEXEC') or die;
 
## Import Joomla Data
jimport('joomla.application.component.controllerform');
jimport('joomla.database.table');
 
## Request controller
class JooSamControllerRequest extends JControllerForm{

	protected $text_prefix = 'Request';
	
	## Save button
	public function save($key = null, $urlVar = null){

		$data = JRequest::getVar('jform', array(), 'post', 'array');
		$songtype = implode(',',$data['songtyp']);
		
		if ($data['id'] == '1'){
			$db =& JFactory::getDBO();
			$query = "
				UPDATE ".$db->nameQuote('#__joosam_request')."
				SET ".$db->nameQuote('reqmsg')." = ".$db->quote($data['reqmsg']).",
					".$db->nameQuote('songtyp')." = ".$db->quote($songtype).",
					".$db->nameQuote('defcat')." = ".$db->quote($data['defcat']).",
					".$db->nameQuote('evtcat')." = ".$db->quote($data['evtcat']).",
					".$db->nameQuote('colora')." = ".$db->quote($data['colora']).",
					".$db->nameQuote('colorb')." = ".$db->quote($data['colorb']).",
					".$db->nameQuote('colorc')." = ".$db->quote($data['colorc']).",
					".$db->nameQuote('frontpagetext')." = ".$db->quote($data['frontpagetext'])."
				WHERE ".$db->nameQuote('id')." = ".$db->quote($data['id'])."; ";
			$db->setQuery($query);
			$result = $db->query();

			if (!$result){
				$this->setMessage(JText::_('COM_JOOSAM_ERROR_SAVE_DATA'), 'warning');
				$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=requests', false));
			}
			else{
				$this->setMessage(JText::_('COM_JOOSAM_REQUEST_SAVED'));
				$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=requests', false));
			}
		}
		else if ($data['id'] != '1'){
			$this->setMessage(JText::_('COM_JOOSAM_NO_CODE_MOD_ALLOWED'));
			$this->setRedirect(JRoute::_('index.php?option=com_joosam&view=requests', false));
		}
	}
}
?>